<?php
error_reporting(0);
require_once("includes/pagetop.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$patharr=explode("/",$_SERVER["REQUEST_URI"]);

$lastvars=end($patharr);

$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);
if(!(isset($_REQUEST['t']) && trim($_REQUEST['t'])!=''))
{
    redirect("home.php");
}

$dnauserqry="select * from af_users where Allyfolio_User_ID=:afuserid  ";
$condition[":afuserid"]=$_REQUEST['t'];
$dnauserinfo=$pdodbobj->fetch_array($pdodbobj->query($dnauserqry,$condition));

if(count($dnauserinfo)==0)
{
    redirect($_SERVER["HTTP_REFERER"]);
}

//echo "<pre>";
//print_r($dnauserinfo);
//echo "</pre>";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | DNA </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>

<script src="js/functions.js"></script>

<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>


<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>



<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>



<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	

	}

	.new tr td{ vertical-align:top}

	

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

	

</style>

</head>



<body>



	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<div class="wrapper row1">
    
    <?php
    require_once("includes/dnaheader.php");
    $sqlquery="select distinct af_users.User_ID,Profile_Pic_Path,Allyfolio_User_ID,Full_Name from af_users,af_user_friends where af_users.User_ID =af_user_friends.User_Friend_ID and (af_user_friends.Status=1 ) and af_user_friends.User_ID ='".$dnauserinfo[0]['User_ID']."' and Profile_Status=0 ";
     
    //$sqlquery="select User_ID,Full_Name,Allyfolio_User_ID,Profile_Pic_Path,Activation_Status from af_users where User_ID in ( select User_Friend_ID from af_user_friends where user_id='".$dnauserinfo[0]['User_ID']."' and Status=1) order by Full_Name asc ";
    //$sqlquery="select User_ID,Full_Name,Allyfolio_User_ID,Profile_Pic_Path,Activation_Status from af_users where User_ID in ( select User_Friend_ID from af_user_friends where user_id='11' and Status=1) order by Full_Name asc ";
    $friendsinfo=$pdodbobj->fetch_array($pdodbobj->query($sqlquery,array("fullname"=>"%".strtolower($query)."%","afuserid"=>"%".strtolower($query)."%","emailid"=>"%".strtolower($query)."%")));
    
    ?>
    
	

    <div class="clearfix"></div>  

    

    

    </div>

    <div class="clearfix"></div>

    <!--=================Header end=======================-->

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <?php include_once("dna_top.php"); ?>

<div class="clearfix"></div>

<?php
if(count($friendsinfo)>0)
{
?>

<div class="dna_nav" style="margin-top:10px; text-align:center;">

		   	Friends

			<div style="clear:both;"></div>

		   </div>

        <div class="clearfix"></div>

		<form name="dnafriendform" method="post" action="dna_friends.php?t=<?php echo $_REQUEST['t']; ?>">

    		<table width="100%" border="0" cellpadding="0" cellspacing="0">
            <?php
            for($i=0;$i<count($friendsinfo);$i++)
            {
                if($i%4==0)
                {
                    echo "<tr>";
                }
                
                $remaintd=0;
                
                if(($i+1)==count($friendsinfo))
                {
                    $remaintd=4-(($i+1)%4);
                }
                
                ?>
                <td>
    
        			<div class="box4">
                        <a href="dna.php?t=<?php echo $friendsinfo[$i]['Allyfolio_User_ID']; ?>"> 
                            <img class="userpiclass" src="<?php if(trim($friendsinfo[$i]['Profile_Pic_Path'])!=""){ echo "uploads/image_crop.php?image=/".$friendsinfo[0]["Profile_Pic_Path"]."&width=150&height=150&cropratio=150:150"; }else{ echo "images/default_user_pic.jpg"; } ?>" height="150px" width="150px" />
                        </a>
        				<div class="abs">
        
        					<span class="dna_name">
                                <a href="dna.php?t=<?php echo $friendsinfo[$i]['Allyfolio_User_ID']; ?>">
                                    <?php echo $friendsinfo[$i]['Full_Name']; ?>
                                </a>
                            </span>
        
        					<span class="dna_check">
        
        						<?php echo getCommonFriends($pdodbobj,$friendsinfo[$i]['User_ID'],$dnauserinfo[0]['User_ID']); ?>m Friends <input type="checkbox" checked="true" id="check_<?php echo $i; ?>" <?php if($dnauserinfo[0]['User_ID']==$_SESSION['Allyfolio_User_ID']){  ?> onclick="return unFriend(<?php echo $i.",".$friendsinfo[$i]['User_ID']; ?>);" <?php } ?> />
        
        					</span>
        
        				</div>
        
        			</div>
                </td>
                <?php
                if($remaintd>0)
                {
                    echo "<td colspan='".$remaintd."'><div class='box4'></div></td>";
                }
                if(($i+1)%4==0)
                {
                    echo "</tr>";
                }
            }
            ?>
            </table>
    </form>
<?php
}
?>

       </div>  
</div>

    </div>

    

    <div class="clearfix"></div>

    <!--=================Body Contain end=======================-->

    </div>

 <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[
    function updatePickcounter(appid,userid,linkval,starcountid)
    {
        if(userid==0)
        {
            alertify.alert('Please login first to pick the app.');
            return false;
        }
        else
        {
            $.ajax({
              cache:false,  
        	  url: "ajax_search/ajax_manageapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
        	  success: function( data ) {
        	    if(parseInt(data)>=0)
                {
                    document.getElementById('pick'+starcountid).innerHTML=trim(parseInt(data).toString());
                    window.open(linkval);
                    return false;
                }
                else
                {
                    alertify.alert("There is an error in picking the app.");
                    return false;
                }
        	  }
        	});
        }
    }
    
    
    function updateEntPickcounter(appid,userid,linkval,starcountid)
    {
        if(userid==0)
        {
            alertify.alert('Please login first to pick the entertainment link.');
            return false;
        }
        else
        {
            $.ajax({
              cache:false,  
        	  url: "ajax_search/ajax_manageentapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
        	  success: function( data ) {
        	    if(parseInt(data)>=0)
                {
                    document.getElementById('pick_ent_'+starcountid).innerHTML=trim(parseInt(data).toString());
                    window.open(linkval);
                    return false;
                }
                else
                {
                    alertify.alert("There is an error in picking the entertainment link.");
                    return false;
                }
        	  }
        	});
        }
    }
    
    function viewEventInfo(evtid,flag)
    {
        document.getElementById(['event_id']).value=evtid;
        if(evtid!="")
        {
            if(flag==0)
            {
                document.eventform.action='event_details.php';
                document.getElementById('actiontype').value="";
            }
            else
            {
                document.getElementById('actiontype').value="editeventinfo";    
            }
            
            document.eventform.submit();
            document.eventform.submit();
        }
    }
    
    function unFriend(checkid,touserid)
    {
        if(!document.getElementById('check_'+checkid).checked)
        {
            alertify.confirm("Are you sure, you want to unfriend?", function (e) {
        		if (e) {
        			alertify.success("You've clicked OK");
        			$.ajax({
                      cache:false,  
                      async:false,
                      url: "ajax_search/ajax_manageRequests.php?action=unfriendrequest&touserid="+touserid,
                	  success: function( data ) {
                	    if(trim(data)=="success")
                        {
                            alertify.alert("You have successfully unfriend this user.");
                            if(document.getElementById('alertify-cover'))
                            {
                                document.getElementById('alertify-cover').style.display='none';
                            }
                            document.dnafriendform.submit();
                        }
                        
                	  }
                	});
        		} else {
        			alertify.error("You've clicked Cancel");
        		}
        	});
            
        }
    }

//]]>
</script>